package com.example.aicooking.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

@Data
@TableName("user_detail")
public class UserDetail {
    @TableId(value = "user_id", type = IdType.INPUT)
    private Long userId;        // 用户ID     // 用户ID
    private Float height;          // 身高(cm)
    private Float weight;          // 体重(kg)
    private Float bmi;            // BMI指数
    private String taste;         // 口味偏好
    private String allergen;      // 过敏原
    private String dietaryRestrictions; // 饮食禁忌

    // BMI状态计算
    public String getBmiStatus() {
        if (bmi == null) {
            return "未知";
        }
        if (bmi < 18.5){
            return "偏瘦";
        }
        if (bmi < 24) {
            return "正常";
        }
        if (bmi < 28) {
            return "偏胖";
        }
        return "肥胖";
    }

    // BMI自动计算
    public void calculateBmi() {
        if (height != null && weight != null && height > 0) {
            // BMI = 体重(kg) / (身高(m))²
            float heightInMeter = height / 100;
            this.bmi = weight / (heightInMeter * heightInMeter);
            // 保留一位小数
            this.bmi = Math.round(this.bmi * 10) / 10f;
        }
    }


    // 获取健康建议
    public String getHealthAdvice() {
        StringBuilder advice = new StringBuilder();

        // BMI建议
        if (bmi != null) {
            if (bmi < 18.5) {
                advice.append("您的体重偏轻，建议适当增加营养摄入。");
            } else if (bmi >= 24) {
                advice.append("您的体重偏重，建议控制饮食，增加运动。");
            } else {
                advice.append("您的体重正常，请继续保持！");
            }
        }

        // 饮食建议
        if (dietaryRestrictions != null && !dietaryRestrictions.isEmpty()) {
            advice.append("\n请注意避免食用: ").append(dietaryRestrictions);
        }

        return advice.toString();
    }
}
